const router = {
    renderView() {
        let state = history.state; 
        console.log(state.path)
        switch(state.path){
            case 'home':
                $("main").html('home')
                break;
            case 'group':
                $("main").html('group')
                break;
            case 'cart':
                $("main").html('cart')
                break;
            case 'mine':
                $("main").html('mine')
                break;
        }
        $(`nav a[href=${state.path}]`).closest('li').addClass('active').siblings().removeClass('active')
    },

    init(){
        let _this = this
        $('nav a').on('click',function(e){
            e.preventDefault()
            let path = $(this).attr('href')
            history.pushState({path},null,path)
            _this.renderView()
        })
        window.addEventListener('popstate',this.renderView)
        window.addEventListener('hashchange',this.renderView)
    }
}

export {
    router
}